package net.jsoft.pms.repository.versionplan;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import net.jsoft.pms.entity.plan.Plan;
import net.jsoft.pms.entity.versionplan.VersionPlan;

@Transactional
public interface VersionPlanRepository extends PagingAndSortingRepository<VersionPlan, Long>, JpaSpecificationExecutor<VersionPlan>
{

    @Query("from Plan where  earlyVersion = :version")
    List<Plan> findPlanByPlanVersion(@Param("version") String version);

    @Query("from Plan where  lateVersion = :version")
    List<Plan> findPlanByPublishedVersion(@Param("version") String version);

    @Query("from VersionPlan where  version = :version")
    VersionPlan findOneByVersion(@Param("version") String version);

    @Query(value = "select * from t_dzswj_versionplan where id = (select id from t_dzswj_versionplan where id > :version  order by id asc limit 1)", nativeQuery = true)
    VersionPlan findNextVersion(@Param("version") long version);

    @Query(value = "select * from t_dzswj_versionplan where id = (select id from t_dzswj_versionplan where id < :version  order by id desc limit 1) ", nativeQuery = true)
    VersionPlan findLastVersion(@Param("version") long version);

   
}
